Author: Norman Rasmussen <norman@rasmussen.co.za>

    Make setupscript work and add teardownscript setting.

--- aiccu.orig/common/aiccu.c
+++ aiccu/common/aiccu.c
@@ -212,9 +212,6 @@
 	fprintf(f, "# Try to automatically login and setup the tunnel?\n");
 	fprintf(f, "automatic %s\n", g_aiccu->automatic ? "true" : "false");
 	fprintf(f, "\n");
-	fprintf(f, "# Script to run after setting up the interfaces (default: none)\n");
-	fprintf(f, "%ssetupscript %s\n", g_aiccu->setupscript ? "" : "#", g_aiccu->setupscript ? g_aiccu->setupscript : "<path>");
-	fprintf(f, "\n");
 	fprintf(f, "# TLS Required?\n");
 	fprintf(f, "requiretls %s\n", g_aiccu->requiretls ? "true" : "false");
 	fprintf(f, "\n");
@@ -231,6 +228,9 @@
 	fprintf(f, "# PID File\n");
 	fprintf(f, "pidfile %s\n", g_aiccu->pidfile);
 	fprintf(f, "\n");
+	fprintf(f, "# Script to run after setting up the interfaces (default: none)\n");
+	fprintf(f, "%ssetupscript %s\n", g_aiccu->setupscript ? "" : "#", g_aiccu->setupscript ? g_aiccu->setupscript : "<path>");
+	fprintf(f, "\n");
 	fprintf(f, "# Make heartbeats (default true)\n");
 	fprintf(f, "# In general you don't want to turn this off\n");
 	fprintf(f, "# Of course only applies to AYIYA and heartbeat tunnels not to static ones\n");
--- aiccu.orig/unix-console/main.c
+++ aiccu/unix-console/main.c
@@ -471,6 +471,11 @@
 	 */
 	if (aiccu_setup(hTunnel, true))
 	{
+		if (g_aiccu->setupscript)
+		{
+			aiccu_exec("%s", g_aiccu->setupscript);
+		}
+
 		/* We need to stay running when doing Heartbeat or AYIYA */
 		if (	strcasecmp(hTunnel->sType, "6in4-heartbeat") == 0 ||
 			strcasecmp(hTunnel->sType, "ayiya") == 0)
